package com.code.wflow.common;

/**
 * @author ggh
 * @date 2022/11/11
 */
public final class RequestContextHolder {
    private static final ThreadLocal<RequestContext> contextHolder = new ThreadLocal<>();

    private RequestContextHolder() {
    }

    public static void clearContext() {
        contextHolder.remove();
    }

    public static RequestContext getContext() {
        RequestContext ctx = contextHolder.get();
        if (ctx == null) {
            ctx = createEmptyContext();
            contextHolder.set(ctx);
        }

        return ctx;
    }

    private static RequestContext createEmptyContext() {
        return new RequestContext();
    }
}
